package com.bqtv.sport.ui.mine

import android.content.Context
import android.content.Intent
import android.view.View
import androidx.recyclerview.widget.GridLayoutManager
import com.bqtv.sport.adapter.PointsMallAdapter
import com.bqtv.sport.adapter.PointsMallSignAdapter
import com.bqtv.sport.app.AppActivity
import com.bqtv.sport.commen.widget.GridItemDecoration
import com.bqtv.sport.databinding.ActivityPointsMallBinding
import com.bqtv.sport.dialog.GoodsDialog
import com.bqtv.sport.dialog.SetTextDialog
import com.hjq.bar.OnTitleBarListener
import com.hjq.bar.TitleBar

class PointsMallActivity : AppActivity<ActivityPointsMallBinding>() {
    private lateinit var signAdapter: PointsMallSignAdapter
    private lateinit var mallAdapter: PointsMallAdapter

    companion object {
        fun start(context: Context) {
            val intent = Intent(context, PointsMallActivity::class.java)
            context.startActivity(intent)
        }
    }

    override fun getViewBinding() = ActivityPointsMallBinding.inflate(layoutInflater)

    override fun initView() {
        binding.rcvSign.layoutManager = GridLayoutManager(this, 7)
        binding.rcvSign.addItemDecoration(
            GridItemDecoration(
                getContext(), 7,
                GridItemDecoration.LineDrawMode.HORIZONTAL, 5, 1
            )
        )
        signAdapter = PointsMallSignAdapter()
        binding.rcvSign.adapter = signAdapter

        binding.rcvExchange.layoutManager = GridLayoutManager(this, 2)
        binding.rcvExchange.addItemDecoration(
            GridItemDecoration(
                getContext(), 2,
                GridItemDecoration.LineDrawMode.HORIZONTAL, 9, 10
            )
        )
        mallAdapter = PointsMallAdapter()
        binding.rcvExchange.adapter = mallAdapter
    }

    override fun initData() {

        signAdapter.submitList(arrayListOf("1", "2", "3", "4", "5", "6", "7"))
        mallAdapter.submitList(arrayListOf("1", "2", "3", "4", "5", "6", "7"))

        initListener()
    }

    private fun initListener() {
        getTitleBar()?.setOnTitleBarListener(object : OnTitleBarListener {
            override fun onRightClick(titleBar: TitleBar?) {
                super.onRightClick(titleBar)
                PointsMallRulesActivity.start(getContext())
            }
        })
        mallAdapter.setOnItemClickListener { adapter, view, position ->
            val goodsDialog = GoodsDialog.Builder(getContext())
            goodsDialog.clickResult = object : GoodsDialog.Builder.ClickResult {
                override fun onConfirmClick(text: String) {
                    GoodsDetailActivity.start(getContext())
                }
            }
            goodsDialog.show()
        }
        binding.tvPointsDetails.setOnClickListener(this)
        binding.tvMyGoods.setOnClickListener(this)
    }

    override fun onClick(view: View) {
        super.onClick(view)
        when (view) {
            binding.tvPointsDetails -> {
                PointsDetailActivity.start(getContext())
            }
            binding.tvMyGoods -> {
                MyExchangeActivity.start(getContext())
            }
        }
    }
}